package com.yuno.mock.strategy;

import com.yuno.mock.dto.ExcelReadRequest;
import java.util.List;

/**
 * 分片策略接口
 * 
 * @author xrm
 * @since 1.0.0
 */
public interface ShardingStrategy {
    
    /**
     * 创建分片
     * 
     * @param request Excel读取请求
     * @param totalRows 总行数
     * @return 分片列表
     */
    List<Shard> createShards(ExcelReadRequest request, long totalRows);
    
    /**
     * 获取策略名称
     * 
     * @return 策略名称
     */
    String getStrategyName();
    
    /**
     * 是否支持该策略
     * 
     * @param strategyName 策略名称
     * @return 是否支持
     */
    boolean supports(String strategyName);
    
    /**
     * 分片信息类
     */
    class Shard {
        /**
         * 分片ID
         */
        private String shardId;
        
        /**
         * 起始行号（从1开始，包含）
         */
        private long startRow;
        
        /**
         * 结束行号（从1开始，包含）
         */
        private long endRow;
        
        /**
         * 分片大小（行数）
         */
        private long size;
        
        /**
         * 工作表名称
         */
        private String sheetName;
        
        /**
         * 工作表索引
         */
        private int sheetIndex;
        
        /**
         * 优先级（数字越小优先级越高）
         */
        private int priority;
        
        /**
         * 预估处理时间（毫秒）
         */
        private long estimatedTimeMs;
        
        public Shard() {}
        
        public Shard(String shardId, long startRow, long endRow, String sheetName, int sheetIndex) {
            this.shardId = shardId;
            this.startRow = startRow;
            this.endRow = endRow;
            this.size = endRow - startRow + 1;
            this.sheetName = sheetName;
            this.sheetIndex = sheetIndex;
            this.priority = 0;
            this.estimatedTimeMs = size * 10; // 简单估算：每行10毫秒
        }
        
        // Getters and Setters
        public String getShardId() {
            return shardId;
        }
        
        public void setShardId(String shardId) {
            this.shardId = shardId;
        }
        
        public long getStartRow() {
            return startRow;
        }
        
        public void setStartRow(long startRow) {
            this.startRow = startRow;
            this.size = this.endRow - startRow + 1;
        }
        
        public long getEndRow() {
            return endRow;
        }
        
        public void setEndRow(long endRow) {
            this.endRow = endRow;
            this.size = endRow - this.startRow + 1;
        }
        
        public long getSize() {
            return size;
        }
        
        public void setSize(long size) {
            this.size = size;
        }
        
        public String getSheetName() {
            return sheetName;
        }
        
        public void setSheetName(String sheetName) {
            this.sheetName = sheetName;
        }
        
        public int getSheetIndex() {
            return sheetIndex;
        }
        
        public void setSheetIndex(int sheetIndex) {
            this.sheetIndex = sheetIndex;
        }
        
        public int getPriority() {
            return priority;
        }
        
        public void setPriority(int priority) {
            this.priority = priority;
        }
        
        public long getEstimatedTimeMs() {
            return estimatedTimeMs;
        }
        
        public void setEstimatedTimeMs(long estimatedTimeMs) {
            this.estimatedTimeMs = estimatedTimeMs;
        }
        
        @Override
        public String toString() {
            return String.format("Shard{id='%s', rows=%d-%d, size=%d, sheet='%s'[%d], priority=%d}", 
                    shardId, startRow, endRow, size, sheetName, sheetIndex, priority);
        }
    }
}